﻿using Digitalmes.Domain.Entities.Mes.Masters;

namespace Digitalmes.Application.Mes.Masters.Workstations.Commands;

/// <summary>
/// 更新工位命令。
/// </summary>
/// <param name="Workstation"></param>
public record UpdateWorkstationCommand(MdWorkstationDto Workstation) : IRequest<IResult<bool>>;

internal sealed class UpdateWorkstationCommandHandler(IRepository<MdWorkstation> repo) : IRequestHandler<UpdateWorkstationCommand, IResult<bool>>
{
    public async Task<IResult<bool>> Handle(UpdateWorkstationCommand request, CancellationToken cancellationToken)
    {
        var ws = request.Workstation.Adapt<MdWorkstation>();
        var ok = await repo.UpdateAsync(ws, m => new
        {
            m.WsName,
            m.WsType,
            m.Sort,
            m.Status,
            m.UpdatedBy,
            m.UpdatedTime,
        }, cancellationToken);
        return Result.From(ok);
    }
}
